//指定房间的东南西北
export enum Direction { North, South, East, West };

//抽象的产品
interface MapSite {
    enter(): void
}

//具体的产品room
export class Room implements MapSite {
    private _sides: MapSite[];
    private _roomNumber: number
    constructor(roomNo: number) {
        this._roomNumber = roomNo
        this._sides = [new Wall, new Wall, new Wall, new Wall]
    }
    public getSide(direction: Direction): MapSite {
        return this._sides[direction];
    }

    public setSide(direction: Direction, mapSite: MapSite): void {
        this._sides[direction] = mapSite;
    }
    enter(): void {
        console.log('进入了房间');
    }
    Clone() {
        return new Room(this._roomNumber)
    }
}
//具体的产品wall
export class Wall implements MapSite {
    enter(): void {
        console.log('墙挡住的');
    }
    Clone() {
        return new Wall()
    }

}

export class Door implements MapSite {
    private _room1: Room
    private _room2: Room
    private _isOpen: boolean

    constructor(r1: Room, r2: Room) {
        this._room1 = r1
        this._room2 = r2
        this._isOpen = false
    }
    enter(): void {
        if (this._isOpen) {
            console.log("通过门进入");
        } else {
            console.log('门是关闭的');
        }
    }
    Initialize(r1: Room, r2: Room) {
        this._room1 = r1
        this._room2 = r2
    }
    otherSideFrom(r: Room): Room | null {
        if (r === this._room1) {
            return this._room2
        } else if (r === this._room2) {
            return this._room1
        }
        return null
    }

    Clone(): Door {
        return new Door(this._room1, this._room2)
    }

}

export class Maze {

    private room: Room[]
    constructor() {
        this.room = []
    }
    addRoom(r: Room): void {
        this.room.push(r)
    }

    getRoom(n: number): Room {
        return this.room[n]
    }

    Clone() {
        return new Maze()
    }
}